<!--# layout("/common/layout.html",{"jsBase":"/js/content/resContentMain/"}){-->

<link rel="stylesheet" href="${ctxPath}/plugins/ueditor/xiumi-ue-v5.css">
<style>
    .layui-form-select dl{
        z-index: 9999;
    }
</style>
<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data"  lay-filter="editform">
    <input type="hidden" name="contentId" id="contentId">
    <!--# if(!(isEmpty(mediaType))){  -->
    <input type="hidden" name="mediaType" value="${mediaType}">
    <!--# } -->
    <br/>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">内容标题</label>
				<div class="layui-input-inline" style="width:512px">
                    <input type="text" name="contentTitle" id="contentTitle" autocomplete="off" class="layui-input" lay-verify="required">
				</div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-inline">
                   <layui:simpleDataSelect name="customerId" value="" data="${customerInfoList}"
                                            attrId="customerId" attrName="customerName" layFilter="customerFilter" id="customer_author" laySearch="true" />
                    <input type="hidden" name="author" id="author" value="圣达信教育"/>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">内容标签</label>
                <div class="layui-input-block" style="width:512px" id="contentTags">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">详情介绍</label>
                <div class="layui-input-block" style="width:512px">
                    <div id="wxin-contentDesc"></div>
                    <input type="hidden" name="contentDesc" id="contentDesc"/>
                </div>
            </div>
        </div>
    </div>

    <layui:image id="cover" tagName="封面" tips="图片格式：400*345"/>
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->

<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/xiumi-ue-dialog-v5.js"></script>

<script>

    let ueditor_config = {
        toolbars: [["undo", "redo", "|", "fontsize", "forecolor", "bold", "italic", "underline", "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight", "|", "directionalityltr", "directionalityrtl", "indent", "|", "simpleupload", "|",  "spechars", "source", "|", "searchreplace", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/content/resContentMain/config",
        autoHeightEnabled: false,
        elementPathEnabled : true,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:400,
        initialFrameWidth:850
    };

    var ue = UE.getEditor('wxin-contentDesc',ueditor_config);
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {
            console.log("upload");
            return '${ctxPath}/content/resContentMain/upload.json';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    }

    Common.initImage();
    layui.extend({
        selectM: '../../../plugins/layui_extends/selectM',
    }).define([ 'form', 'laydate', 'table','selectM','resContentMainApi'], function(exports) {
    var form = layui.form;
    var resContentMainApi = layui.resContentMainApi;
    var index = layui.index;
    var isNew = true;
    var selectM = layui.selectM;
    var tagData = ${resTagList};
    var provinceId = 0;
    var moduleId = 0;
    <!--# if(!(isEmpty(resContentMainJson))){  -->
    isNew = false;
    <!--# } -->

        form.on('select(lay)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            console.log("test");
        });

        $("#lay").click(function(){
          console.log("test"+$(this).val());
         });
    var view = {
        initCol:function(){
            var provinceId1 = $("#provinceId").val();
            var moduleId1 = $("#moduleId").val();
            if (provinceId1!="" && moduleId1!="") {
                if (provinceId1!=provinceId || moduleId1!=moduleId) {
                    provinceId = provinceId1;
                    moduleId = moduleId1;
                    $("#contentTypes").empty();
                    var colM = selectM({
                        //元素容器【必填】
                        elem: '#contentTypes'
                        //候选数据【必填】
                        ,data: "getColumns.json?moduleId="+moduleId+"&provinceId="+provinceId
                        //默认值
                        ,selected: [${resContentMain.contentType!}]
                        //最多选中个数，默认5
                        ,max : 6
                        //input的name 不设置与选择器相同(去#.)
                        ,name: 'contentType'
                        //值的分隔符
                        ,delimiter: ','
                        //候选项数据的键名
                        ,field: {idName:'colId',titleName:'colName'}
                    });
                }
            }
        },
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            form.on('select(colFilter)', function(data){
                view.initCol();
            });
            var tagIns2 = selectM({
                //元素容器【必填】
                elem: '#contentTags'
                //候选数据【必填】
                ,data: tagData
                //默认值
                ,selected: [${selectedTags!}]
                //最多选中个数，默认5
                ,max : 1
                //input的name 不设置与选择器相同(去#.)
                ,name: 'contentTags'
                //值的分隔符
                ,delimiter: ','
                //候选项数据的键名
                ,field: {idName:'tagName',titleName:'tagName'}
            });
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                document.getElementById("contentDesc").value=UE.getEditor('wxin-contentDesc').getContent();
                form.on('submit(form)', function(){
                    resContentMainApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });
            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }
    }
    view.init();
    <!--# if(!(isEmpty(resContentMainJson))){  -->
    var formJson = ${resContentMainJson};
    form.val("editform",formJson);
    ue.ready(function() {
        UE.getEditor('wxin-contentDesc').setContent(formJson.contentDesc);
    });
    view.initCol();
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    <!--# } -->
    form.on('select(customerFilter)', function(data){
        $("#author").val($("#customer_author").find("option:selected").text());
    });
});
</script>
<script type="application/javascript">


    // 编辑
    // setTimeout(function () {
    //     var bjcontentDesc=  document.getElementById("contentDesc").value;
    //     UE.getEditor('wxin-contentDesc').setContent(bjcontentDesc);
    // },1000);
</script>
